package com.jk.service.impl;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

import com.jk.pojo.Project;
import com.jk.pojo.Recruit;
import com.jk.service.RecruitService;

@Service
@Transactional
public class RecruitServiceImpl extends BaseServiceImpl<Recruit> implements RecruitService {

	@Transactional(readOnly=true)
	@Override
	public List<Recruit> queryList(String name, String firstTimeStr,String endTimeStr,String industryId,String path) throws Exception {
		Example example = new Example(Recruit.class);
    	Criteria criteria = example.createCriteria();
    	if(StringUtils.isNotEmpty(firstTimeStr) && StringUtils.isNotEmpty(endTimeStr)){
    		Date firstTime = DateUtils.parseDate(firstTimeStr+" 00:00:00", new String[]{"yyyy-MM-dd HH:mm:ss"});
    		Date endTime = DateUtils.parseDate(endTimeStr+" 23:59:59", new String[]{"yyyy-MM-dd HH:mm:ss"});
    		criteria.andBetween("sendTime", firstTime, endTime);
    	}
    	if("_job".contains(path)){
			criteria.andEqualTo("recruitType", 1);
			if(StringUtils.isNotEmpty(name)){
	    		criteria.andLike("name", "%"+name+"%");
	    	}
		}else if ("_industry".contains(path)) {
			criteria.andEqualTo("recruitType", 2);
			if(StringUtils.isNotEmpty(industryId)){
	    		criteria.andEqualTo("industryId",Long.valueOf(industryId));
	    	}
		}
		return this.selectByExample(example);
	}

}
